define(function (require, exports, module) {
    var myPub = require('./public');
    var payPub = require('./submit_pay');

    var oWindow = $(window);
    var oSildeNavUl = $('.js_sildeNavUl');              // 导航滚动条ul
    var oOrderSw = $('.js_swiper');
    var oHeader = $('.js_headerBox');                     // 头部
    var oContain = $('.orderContain');

    var oSlidePageWrap = $('.js_slidePageWrap');        // 滑动页面
    var oOrderBtnEvent = $('.js_orderBtnEvent');        // 操作订单下方按钮
    var oSlidePageScroll = $('.js_slidePageScroll');      // 导航滚动条容器
    var oGoTop = $('.js_goTop');                    // 回到顶部
    var oSildeNavScroll = $('.js_sildeNavScroll');  // 导航滚动条容器
    var oSideBox = $('.js_sideBox');		        // 侧边按钮框
    var oLoadingPage = $('.js_loadingPage');
    var nDisScrollLi = 0;                           // 导航滚动偏移值
    var resizeTimer = null;
    var lazLoading = new myPub.lazLoadingImg();

    // 全局 订单类型
    var sign = ['all','wait4Payment','wait4Delivery','wait4Receive','tradeSuccess'];
    // 获取数据路径
    var orderUrl = '/member/order/showTypePaymentV4';
    var orderUrl2 = 'static_v4/js/dataJson/goodsData.json';
    var storeDetailUrl = '/m/g/supplier/1.0/isOverSeaSupplier';        // 判断是进入海外店铺还是进入普通店铺的接口


    // 回到过顶部
    oGoTop.hammer().on('tap', function () {
        var oSlidePageScroll = $('.js_slidePageScroll');
        oSlidePageScroll.eq(pageData.navIndex).stop().animate({scrollTop: '0'}, 250);
        oHeader.css({'top': 0}).find('.js_sildeNav').removeClass('active');
        myPub.HamstopPropaga();
    });
    //按钮的点击事件绑定给最大的wrap盒子
    oOrderBtnEvent.hammer().on('tap', function (e) {
        var _btnA = $(e.gesture.target);

        var _typeNum = _btnA.attr('_type');
        var oId = _btnA.attr('oId');
        var orderSn = _btnA.attr('_orderSn');

        var imgUrl = _btnA.parents('.onOrderFoot').siblings('.goods_showChangeBox').find('.js_lazyImg').attr('src');

        if (_typeNum !== undefined)     {
            myPub.HamstopPropaga();
        }
        switch (_typeNum * 1) {
            // 0 删除订单
            case 0:
                myPub.askLayer('确认要删除订单吗？ ', function () {
                    //    确认的回调
                    G_JSON_GET('/member/order/delete', {"orderId": oId}, function (data) {
                        if (data.status == "success") {
                            location.reload();
                        } else {
                            myPub.TipLayer(data.message);
                        }
                    });
                    myPub.LayerCloseAll();
                }, function () {
                    //    取消的回调
                }, null, function () {
                    //    callback
                });
                break;
            // 1 提醒发货
            case 1:
                var styleTitle = "提醒发货成功!请耐心等候";
                var remindStyle = "background-color:rgba(0,0,0,0.5); color:#fff; border:none; border-radius: 5px; min-width:50%"
                myPub.TipLayer(styleTitle, remindStyle);
                break;
            // 2.查看物流
            case 2:
                //跳转到查看物流页面
                window.location.href = "/h/goodsafter/expressDetail/" + orderSn;
                break;
            // 3 确认收货
            case 3:
                myPub.askLayer('确认要收货吗？ ', function () {
                    //    确认的回调
                    G_JSON_GET('/member/order/receive', {"orderId": oId}, function (data) {
                        if (data.status == "success") {
                            //location.reload();
                            // window.location.href = '/shop/goodsComment/comment/'+oId;

                            window.location.href= "/h/goodsafter/applyAppraisal/" + oId + '?picImgUrl=' + imgUrl;

                        } else {
                            myPub.TipLayer(data.message);
                        }
                    });
                    myPub.LayerCloseAll();
                }, function () {
                    //    取消的回调
                }, null, function () {
                    //    callback
                });
                break;
            // 4 立即评价
            case 4:
                // window.location.href= "/shop/goodsComment/comment/"+oId;

                window.location.href= "/h/goodsafter/applyAppraisal/" + oId + '?picImgUrl=' + imgUrl;
                // G_JSON_GET('/shop/goodsComment/find_comment/'+oId+'?receiveDate='+_btnA.attr('receiveDate'), null, function (data) {
                //     if (data.status == "first") {
                //     }else if (data.status == "append") {
                //         window.location.href= "/shop/goodsComment/appendComment/"+oId;
                //     } else {
                //         myPub.TipLayer(data.message);
                //     }
                // });
                break;
            // 5 去支付
            case 5:
                var payUrl = "/shop/payment/continuePay";
                var data = {paymentId:oId};
                payPub.submitPay(payUrl,data);
                break;
            // 6 取消订单
            case 6:
                myPub.askLayer('确认要取消订单吗？ ', function () {
                    G_JSON_POST('/shop/payment/cancelNoPayOrder', {paymentId:oId}, function (data) {
                        if (data.status == "success") {
                            location.reload();
                        } else {
                            myPub.TipLayerEnd(data.message, 'no', function () {
                                location.reload();
                            });
                        }
                    });
                    myPub.LayerCloseAll();
                }, function () {
                    //    取消的回调
                }, null, function () {
                    //    callback
                });
                break;
            // 7 分享给TA
            case 7:
                window.location.href = "/shop/gift/sharePage/" + oId;
                break;
            //8 追加评论
            case  8:
                window.location.href= "/shop/goodsComment/appendComment/"+oId;
                break;
            case  9:
                window.location.href= "/super/distributorDownLoad";
                break;
            default:
                break;
        }
    });

    module.exports = {
        init: function (names, counts) {
            pageData.initHistoryData(names.length);
            myOrderSwiper.initOrderSwiper(names,counts);
            myOrderSwiper.myOrderInit(true);
            myOrderSwiper.ScrollPage();

            // 页面尺寸修改
            oWindow.on('resize', function () {
                if (resizeTimer) {
                    clearTimeout(resizeTimer)
                }
                resizeTimer = setTimeout(function () {
                    myOrderSwiper.myOrderInit(true);
                }, 400);
            });

            // 初始化 分页位置或者数据
            if(pageData.navIndex != 0){
                myOrderSwiper.oSlidePageMain.slideTo(pageData.navIndex, 100);
            }else{
                pageData.swiperLoadData(0);
            }

            oWindow.unload(function(){
                pageData.storeSession();
            });
        }
    }

    var pageData = {
        navIndex: 0,                    // 导航选中索引  需要放入Session
        pagearr: [1],                   // 每个分页的翻页数  需要放入Session
        pageSCroll: [0],                // 每个分页滚动高度  需要放入Session

        loadPage: [0],                  // 每个分页已经加载的页码
        pageFinish:[false],             // 每个分页是否加载完成
        swiperScroll:[0],
        pageLimit:20,

        /**
         * 初始化方法 从Session中加载数据 没有就初始化
         * @param initNav 需要直接定位的分页标签
         */
        initHistoryData:function (navLength) {
            var _this = this;
            var _LocalIndex = 0;
            for (var i = 0; i < navLength; i++) {
                _this.pagearr[i] = 1;
                _this.pageSCroll[i] = 0;
                _this.loadPage[i] = 0;
                _this.pageFinish[i] = false;
                _this.swiperScroll[i] = 0;
            }
            var sessionNavIndex = sessionStorage.getItem("order_navIndex");
            sessionNavIndex || sessionNavIndex!=null ? parseInt(sessionNavIndex) : sessionNavIndex = _LocalIndex;
            _this.navIndex = sessionNavIndex;
            // _this.showDebugData();
            var localNavIndex = localStorage.getItem("orderNav_index");
            if(localNavIndex != null) {
                switch (localNavIndex) {
                    case 'dzf':
                        _LocalIndex = 1;
                        break;
                    case 'dfh':
                        _LocalIndex = 2;
                        break;
                    case 'dsh':
                        _LocalIndex = 3;
                        break;
                    case 'jycg':
                        _LocalIndex = 4;
                        break;
                    case '0':
                        _LocalIndex = 0;
                        break;
                    default:
                        _LocalIndex = 10;
                }
                _this.navIndex = _LocalIndex;
                if(_LocalIndex == 10){
                    if(sessionNavIndex && sessionNavIndex!=null){
                        _this.navIndex = parseInt(sessionNavIndex)
                    }else{
                        _this.navIndex = 0
                    }
                }
                localStorage.removeItem("orderNav_index");
            }

            var sessionPagearr = sessionStorage.getItem("order_pagearr");
            if(sessionPagearr != null){
                var pagearrNum = sessionPagearr.split(',');
                for (var i = 0; i < pagearrNum.length; i++) {
                    _this.pagearr[i] = parseInt(pagearrNum[i]);
                }
            }
            var sessionPageSCroll = sessionStorage.getItem("order_pageSCroll");
            if(sessionPageSCroll != null){
                var pageSCrollNum = sessionPageSCroll.split(',');
                for (var i = 0; i < pageSCrollNum.length; i++) {
                    _this.pageSCroll[i] = parseInt(pageSCrollNum[i]);
                }
            }
            _this.storeSession();
        },
        /**
         * 保存数据到Session中
         */
        storeSession:function () {
            var _this = this;
            // _this.showDebugData();

            sessionStorage.setItem("order_navIndex", _this.navIndex);
            sessionStorage.setItem("order_pagearr", _this.pagearr);
            sessionStorage.setItem("order_pageSCroll", _this.pageSCroll);
        },
        /**
         * 滑动加载数据方法
         */
        swiperLoadData:function (index) {
            var _this = this;
            // _this.showDebugData();
            _this.initHistoryData();
            _this.navIndex = index;
            if(_this.pageFinish[index] || _this.loadPage[index] > 0){
                var oSlidePageScroll = $('.js_slidePageScroll');
                // console.log("scroll  %o  index  %o  oSlidePageScroll  %o",_this.pageSCroll[index],index,oSlidePageScroll);
                oSlidePageScroll.eq(index).scrollTop(_this.pageSCroll[index]);
                return;
            }
            _this.lockScrollHeight(index);
            _this.asynGetOrderData(index,0,_this.pagearr[index],function () {
                // _this.showDebugData();
                _this.swiperScrollHeight(index);
            });
        },
        /**
         * 滚动下拉加载数据方法
         */
        scrollLoadData:function (index) {
            var _this = this;
            // _this.showDebugData();
            if(_this.pageFinish[index]){
                return;
            }
            _this.asynGetOrderData(index,_this.loadPage[index],1,function () {
                _this.pagearr[index]++;
               // console.log(_this.pagearr)
            });
            _this.storeSession();
        },
        /**
         * 异步请求订单数据
         * @param startPage 从第几页开始加载
         * @param page 加载几页数据
         */
        asynGetOrderData:function (index,startPage, page, fn) {
            var _this = this;
            var type = sign[index];
            var pageLimit = 20;
            var start = startPage * _this.pageLimit;
            var limit = page * _this.pageLimit;
            G_JSON_POST(orderUrl, {type:type,start:start,limit:limit}, function (data) {
                if (data.status == "success") {
                    var dataOrderList = data.orderList;

                    var dataSupplierMap = data.supplierMap;

                    orderHtml.oneOrderHtml(index, dataOrderList, dataSupplierMap);

                    if(dataOrderList.length <= 0){//当请求的数据为0时，表示已经没有数据了，不能用limit来判断，有可能是通过paymentOrderId来判断的，数据会大于或者小于limit
                        _this.pageFinish[index] = true;
                    }
                    if(dataOrderList.length > 0){
                      //  page++;
                      //  console.log(page)
                      //  _this.pagearr[index] += page;
                       // _this.pagearr[index] += page;
                        if (fn) fn();
                    }
                   // if (fn) fn();
                    data = null;
                    dataOrderList = null;
                }else{
                    if (fn) fn();
                }
            }, function () {
                oLoadingPage.show();
            }, function (data) {
                var oSlidePageScroll = $('.js_slidePageScroll');
                if(data.length == 0 && start == 0){
                    oSlidePageScroll.eq(index).find('.js_transaction').append(orderHtml.noOrderPage());
                }
                _this.loadPage[index] = _this.pagearr[index];
                oLoadingPage.hide();
                if(data.orderList){
                    if(data.orderList.length < _this.pageLimit){
                        _this.pageFinish[index] = true;
                    }
                }else if(data.length == 0){
                    _this.pageFinish[index] = true;
                }
            });
        },
        /**
         * 锁定一下高度切换
         */
        lockScrollHeight:function (index) {
            var _this = this;
            _this.swiperScroll[index] += 1;
            // console.log("lockScrollHeight %o",_this.swiperScroll[index]);
        },
        /**
         * 切换标签或数据加载完成后 滚动到指定的高度
         */
        swiperScrollHeight:function (index) {
            var _this = this;
            _this.swiperScroll[index] -= 1;
            // console.log("swiperScrollHeight %o",_this.swiperScroll[index]);
            if(_this.swiperScroll[index] == 0){
                var oSlidePageScroll = $('.js_slidePageScroll');
                oSlidePageScroll.eq(index).scrollTop(_this.pageSCroll[index]);
            }
        },
        showDebugData:function () {
            console.log("navIndex == %o",pageData.navIndex);
            console.log("pagearr == %o",pageData.pagearr);
            console.log("pageSCroll == %o",pageData.pageSCroll);
            console.log("loadPage == %o",pageData.loadPage);
            console.log("pageFinish == %o",pageData.pageFinish);
            console.log("pageFinish == %o",pageData.swiperScroll);
        },

        // 判断是进入海外店铺还是进入普通店铺的接口
        goToStoreDetail: function (supplierId) {
            var _this = this;
            G_JSON_POST(storeDetailUrl,{'supplierId':supplierId},function (data) {
                var _data = data.data;
                var _ret = data.ret;
                // console.log('data',_data,_ret);
                if(_ret.code=='0'){
                    if(_data){
                        // 海外馆商家
                        window.location.href =  BASE_URL +'/h/store/storehome?supplierId='+ supplierId ;
                    }
                    else{
                        // 普通商家
                        window.location.href =  BASE_URL +'/h/store/normalStore/'+ supplierId ;
                    }
                }
                else{
                    // 如果请求不到就跳转普通商家
                    window.location.href =  BASE_URL +'/h/store/normalStore/'+ supplierId ;
                }
            })
        }
    };

    //我的订单的各个方法
    var myOrderSwiper = {
        oSlidePageMain: '',
        nHeaderHeight: 0,//
        time_Scroll: null,           // 滚动计时器

        initOrderSwiper:function (names,counts) {
            var $this = this;
            // 插入slide
            for (var i = 0; i < names.length; i++) {
                oSlidePageWrap.append('<div class="swiper-slide js_slidePageScroll"><section class="myOrderAll"><div class="transaction js_transaction"></div></section></div>');
            }
            $this.oSlidePageMain = oOrderSw.swiper({
                pagination: oSildeNavUl[0],
                // autoHeight: true, //高度随内容变化
                observe: true,
                observeParents: true,
                // threshold:100,
                touchAngle: 20,
                paginationClickable: true,
                paginationBulletRender: function (swipe, index, className) {
                    //添加导航
                    if(counts[index] > 0){
                        return '<li class="' + className + ' Bflex1"><a>' + names[index] + '</a><i class="record js_showNum">' + counts[index] + '</i></li>';
                    }else{
                        return '<li class="' + className + ' Bflex1"><a>' + names[index] + '</a></li>';
                    }
                },
                onSlideChangeStart: function (swiper) {
                    var index = swiper.activeIndex;
                    $this.oSlidePageMain.detachEvents();
                    pageData.lockScrollHeight(index);
                    // 请求加载广告
                    pageData.swiperLoadData(index);
                },
                onSlideChangeEnd: function (swiper) {
                    var oSlidePageScroll = $('.js_slidePageScroll');
                    var index = swiper.activeIndex;
                    oSlidePageScroll.find('.myOrderAll').hide().eq(index).show();

                    myOrderSwiper.myOrderInit(false);
                    //
                    lazLoading.DestroyLazLoadingImg();
                    lazLoading.AddLazLoadingImg(oSlidePageScroll[index]);

                    pageData.storeSession();

                    $this.oSlidePageMain.attachEvents();

                    pageData.swiperScrollHeight(index);
                }
            });
        },

        myOrderInit: function (bOff) {
            var oSlidePageScroll = $('.js_slidePageScroll');
            if (bOff) {
                oContain.css({'padding-top': 0});
                oSlidePageScroll.css({
                    'height': oWindow.height() - oHeader.height(),
                    'padding-top': oHeader.outerHeight(true)
                });
            }
            oSideBox.stop().animate({'right': '-3.5rem'}, 300);
        },
        // 滚动隐藏搜索
        ScrollPage: function () {
            var _this = this;
            var oSlidePageScroll = $('.js_slidePageScroll');
            var minScrHeight = 300;

            _this.nHeaderHeight = parseInt(oHeader.outerHeight(true));
            oSlidePageScroll.off('scroll');
            oSlidePageScroll.on('scroll', function () {
                var afterScroll = $(this).scrollTop();
                // 滚动页面距离底部300像素 延迟150毫秒加载数据
                clearTimeout(_this.time_Scroll);
                _this.time_Scroll = setTimeout(function () {
                    var index = pageData.navIndex;
                    // 设置缓存记录
                    pageData.pageSCroll[index] = afterScroll;
                    pageData.storeSession();
                    // 显示隐藏回到顶部侧边框
                    _this.ShowGoTop(afterScroll);

                    if (oSlidePageScroll[index].scrollHeight - afterScroll - oSlidePageScroll.height() < minScrHeight) {
                        // 设置翻页到最后一页 返回
                        if(pageData.pageFinish[index]) {
                            oSlidePageScroll.eq(index).find('.js_loadingBtn').hide().eq(0).show();
                            return;
                        }
                        pageData.scrollLoadData(index);
                    }
                }, 150);
            })

        },
        // 显示回到顶部按钮
        ShowGoTop: function (scrollTop) {
            scrollTop > 300 ? oSideBox.stop().animate({'right': 0}, 300) : oSideBox.stop().animate({'right': '-3.5rem'}, 300);
        },

        // 点击进入店铺详情页面要判断是否是海外店铺
        goToStoreEvent: function(){
            $('.js_goToStore').on('click',function () {
                var supplierId = $(this).attr('data-supplierId');
                pageData.goToStoreDetail(supplierId);
            })
        }
    }
    //拼接的html
    var orderHtml = {
        oneOrderHtml: function (iNow, dataOrderList, dataSupplierMap) {
            var _this = this;
            var oSlidePageScroll = $('.js_slidePageScroll')
            var shtmlBox = '';

            var orderArray = [];
            var orderMap = {};
            for (var i = 0; i < dataOrderList.length; i++) {
                var dataOrder = dataOrderList[i];
                // 代付款的订单特殊处理 如果是同一购物车购买的订单合并到一起
                if('NOPAY' == dataOrder.orderStatus){
                    var orderArr = orderMap[dataOrder.paymentId];
                    if(orderArr == null){
                        orderArr = [];
                        orderMap[dataOrder.paymentId] = orderArr;
                    }
                    orderArr.push(dataOrder);
                }else{
                    orderArray.push([dataOrder]);
                }
            }
            // 将合并好的代付款订单也放进数组里
            for(var key in orderMap){
                // orderArray.push(orderMap[key]);
                orderArray.unshift(orderMap[key]);
            }

            var curTime = new Date().getTime();
            for (var i = 0; i < orderArray.length; i++) {
                //注意头部与列表和底部要传入的数据可能不一样
                var orderArr = orderArray[i];

                var supplier = dataSupplierMap[orderArr[0].supplierId];
                // 获取订单合并的头部 未付款的订单按照购物车合并 其他的按照 商家合并
                var orderGroupHtml;
                if('NOPAY' == orderArr[0].orderStatus){
                    orderGroupHtml = '<p>共' + '<span class="">' + orderArr.length + '</span>' + '件商品' + '</p>';
                }else{
                    if('MULTIGIFT' == orderArr[0].orderType ||'GIFT' == orderArr[0].orderType){
                        orderGroupHtml = [  '<a class="js_goToStore" data-supplierId="'+supplier.supplierId+'">',
                            '   <span class="tip_sendGift">送礼</span>',
                            '   <span class="icon_store iconStyle"></span>',
                            '   <span class="orderShopName">' + supplier.nickName + '</span>',
                            '</a>'].join("");
                    }else if (orderArr[0].orderSource == 'SUPER_TT' || orderArr[0].orderSource == 'SUPER_QJ' || orderArr[0].orderSource == 'SUPER_QT'){
                        orderGroupHtml = [  '<a class="js_goToStore" data-supplierId="'+supplier.supplierId+'">',
                            '   <span class="tip_sendGift">批</span>',
                            '   <span class="icon_store iconStyle"></span>',
                            '   <span class="orderShopName">' + supplier.nickName + '</span>',
                            '</a>'].join("");
                    } else {
                        orderGroupHtml = [  '<a class="js_goToStore" data-supplierId="'+supplier.supplierId+'">',
                            '   <span class="icon_store iconStyle"></span>',
                            '   <span class="orderShopName">' + supplier.nickName + '</span>',
                            '</a>'].join("");
                    }
                }
                // 订单类型
                var orderStatusText;
                if('2' == orderArr[0].giftOrderShowType){
                    var remainSecond = parseInt(orderArr[0].remainSecond);
                    if(remainSecond>0 && orderArr[0].giftRemainQty > 0){
                        orderStatusText = '距订单关闭还剩 <span class="jsAddressTimer" data-timer="' + remainSecond + '"></span>';
                    }else if(remainSecond>0 && orderArr[0].giftRemainQty == 0){
                        orderStatusText = '<span>待发货</span>';
                    } else{
                        orderStatusText = '<span>'+orderArr[0].giftOrderStatusStr+'</span>';
                    }
                }else{
                    switch (orderArr[0].orderStatus){
                        case 'NOPAY' : orderStatusText = '待付款';break;
                        case 'PAYFINISH' : orderStatusText = '待发货';break;
                        case 'SHIPPED' : orderStatusText = '待收货';break;
                        case 'FINISHED' : orderStatusText = '交易完成';break;
                        case 'WAITING_FILL_ADDR' :
                            var remainSecond = parseInt(orderArr[0].remainSecond);
                            orderStatusText = '待TA填地址 <span class="jsAddressTimer" data-timer="' + remainSecond + '"></span>';
                            break;
                        case 'CANCEL' :
                        case 'OVERTIME' :
                        case 'CLOSEED' :
                            orderStatusText = '交易关闭';break;
                    }
                }

                var totalWaitPayAmount = 0;
                var totalAmount = 0;
                for(var idx=0;idx<orderArr.length;idx++){
                    totalWaitPayAmount += orderArr[idx].platformAmount ;
                    totalAmount += orderArr[idx].paidAmount + orderArr[idx].postFee;
                }
                var orderBtn;
                if('NOPAY' == orderArr[0].orderStatus){
                    orderBtn = ['<div class="waitPayBtn orderAllBtn HBox">',
                        '   <p class="Bflex1 waitPayText">',
                        '       <span>需支付:</span>',
                        '       <span class="needPayNum">',
                        '           <i>￥</i><em class="">' +totalWaitPayAmount.toFixed(2) + '</em>',
                        '       </span>',
                        '   </p>',
                         '   <button class="" type="button" _type="6" oid="' + orderArr[0].paymentId + '">取消订单</button>',
                        '   <button class="redBtn" type="button" _type="5" oid="' + orderArr[0].paymentId + '">去支付</button>',
                        '</div>'].join("");
                }else {
                    orderBtn = '<div class="transacSuccBtn orderAllBtn HBox">';
                    orderBtn += '<div class="Bflex1"></div>';
                    if (orderArr[0].orderSource == 'SUPER_TT' || orderArr[0].orderSource == 'SUPER_QJ' || orderArr[0].orderSource == 'SUPER_QT'){
                        orderBtn += '<button class="" style="width: 6.8rem" type="button" _type="9">批量下载运单</button>';
                    }
                    if('FINISHED' == orderArr[0].orderStatus || 'OVERTIME' == orderArr[0].orderStatus
                        || 'CLOSEED' == orderArr[0].orderStatus){
                        orderBtn += '<button class="" type="button" _type="0" oid="' + orderArr[0].id + '">删除订单</button>';
                    }
                    if('WAITING_FILL_ADDR' == orderArr[0].orderStatus){
                        orderBtn += '<button class="redBtn" type="button" _type="7" oid="' + orderArr[0].paymentId + '">分享给TA</button>';
                    }
                    if('PAYFINISH' == orderArr[0].orderStatus){
                        orderBtn += '<button type="button" _type="1" oid="' + orderArr[0].id + '">提醒发货</button>';
                    }
                    if('GIFT' != orderArr[0].orderType && ('SHIPPED' == orderArr[0].orderStatus || 'FINISHED' == orderArr[0].orderStatus)){
                        orderBtn += '<button class="" type="button" _type="2" oid="' + orderArr[0].id + '" _orderSn="'+orderArr[0].orderSn+'">查看物流</button>';
                    }
                    if('SHIPPED' == orderArr[0].orderStatus){
                        orderBtn += '<button class="redBtn" type="button" _type="3" oid="' + orderArr[0].id + '">确认收货</button>';
                    }
                    if('FINISHED' == orderArr[0].orderStatus){
                        // console.log("ces1 ++++"+orderArr[0].isGgoodsComment);
                        if (orderArr[0].isGgoodsComment == "1"){
                            orderBtn += '<button class="redBtn" type="button" _type="4" oid="' + orderArr[0].id + '" receiveDate="' + orderArr[0].receiveDate +'">评价有礼</button>';
                        }else if (orderArr[0].isGgoodsComment == "2"){
                            // console.log("ces2 ++++"+orderArr[0].isGgoodsComment);
                            orderBtn += '<button class="redBtn" type="button" _type="8" oid="' + orderArr[0].id + '" receiveDate="' + orderArr[0].receiveDate +'">追加评价</button>';
                        }else  if (orderArr[0].isGgoodsComment == "3"){
                            //已经追评
                            // console.log("ces3 ++++"+orderArr[0].isGgoodsComment);
                        }
                    }
                    orderBtn += '</div>';
                }

                var orderFooterHtml;
                if('2' == orderArr[0].giftOrderShowType){//不用显示
                    orderFooterHtml = "";
                }else{
                    var receiverHtml;
                    if('1' == orderArr[0].giftOrderShowType){
                        receiverHtml ='<div class="getGiftUser"><span>领取者：'+orderArr[0].giftReceiver+'</span></div>';
                    }else{
                        receiverHtml = '';
                    }
                    orderFooterHtml = ['       <div class="onOrderFoot">',
                        '           <div class="seletPrice borBEA HBox">',
                        receiverHtml,
                        '               <p class="Bflex1">',
                        '                   <span class="selPriLeft">共<i>' + orderArr.length + '</i>件商品</span>',
                        '                   <span class="selPriTotal">小计：<em>￥</em><span class="sumPrice">' + totalAmount.toFixed(2) +'</span></span>',
                        '               </p>',
                        '           </div>',
                        '           <div class="orderBtnBox">',
                        orderBtn,
                        '           </div>',
                        '       </div>'].join("");
                }
                var multiGiftClass = "";
                if('2' == orderArr[0].giftOrderShowType){//不用显示
                    multiGiftClass = "backWhite moreSendGift";
                }
                shtmlBox += [
                    '<div class="transactionSuc '+multiGiftClass+'">',
                    '   <div class="myOrderTranT backWhite">',
                    '       <div class="myOrderShop myFlex myBetween borBEA">',
                    '           <div class="myOrderShopL colTT HBox">',
                    orderGroupHtml,
                    '           </div>',
                    '           <div class="myOrderShopR myFlex colFT">',
                    '               <span>' + orderStatusText + '</span>',
                    '           </div>',
                    '       </div>',
                    orderHtml.orderItemHtml(orderArr),
                    orderFooterHtml,
                    '   </div>',
                    '</div>'].join("");
            }
            var $shtmlBox = $(shtmlBox);
            oSlidePageScroll.eq(iNow).find('.js_transaction').append($shtmlBox);

            $shtmlBox.find('.jsAddressTimer').each(function () {
                var $timerBox = $(this);
                _this.gitfOrderTimer($timerBox);
            });

            // 执行判断店铺页面链接的方法
            myOrderSwiper.goToStoreEvent();



            //每次拼接完都绑定一次懒加载
            lazLoading.DestroyLazLoadingImg();
            lazLoading.AddLazLoadingImg(oSlidePageScroll[iNow]);
        },
        orderItemHtml: function (orderArr) {
            var shtml = '';
            //可能有很多个商品
            for (var i = 0; i < orderArr.length; i++) {
                var order = orderArr[i];
                for(var idx=0;idx<order.orderItemVoList.length;idx++){
                    var orderItem = order.orderItemVoList[idx];
                    var href = BASE_URL + '/shop/pay/order_view?orderSn=' + order.orderSn + '&orderStatus=' + order.orderStatus;
                    if('NOPAY' == order.orderStatus){//首先判断是否是待支付的单
                        href = "/shop/pay/order_confirm?paymentId=" + order.paymentId;
                    }else if('2' == order.giftOrderShowType){
                        href = "/shop/gift/multiGiftOrderEntryDetail?paymentOrderId=" + order.paymentId;
                    }
                    var productNameAreaHtml;
                    var productPriceAreaHtml;
                    var shareTaHtml;
                    if('2' == order.giftOrderShowType){
                        var remainSecond = parseInt(order.remainSecond);
                        productPriceAreaHtml  = [
                            '           <div class="priceArea_price HBox">',
                            '               <p class="priceAreaBox Bflex1"><span class="goodsPriceOld">￥' + orderItem.productPrice + '</span></p>',
                            '           </div>'].join("");
                        if(remainSecond>0){
                            productNameAreaHtml = [
                                '<div class="Bflex1 priceArea_name">',
                                '<h4>' + orderItem.goodsName + '</h4>',
                                '<p class="smallFont_tip">',
                                '<span>剩余'+order.giftRemainQty+'个未领取</span>',
                                '<span>/</span>',
                                '<span>共'+order.giftTotalQty+'个</span>',
                                '</p>',
                                '</div>'].join("");
                            if (order.giftRemainQty > 0){
                                shareTaHtml = '<p class="shareTABtn"><a href="/shop/gift/sharePage/'+order.paymentId+'" class="btnStyle btn_BorderGray">分享给Ta</a></p>';
                            }

                            // shareTaHtml = '<button class="redBtn" type="button" _type="7" oid="' + order.paymentId + '">分享给TA</button>';
                        }else{
                            if(order.giftRemainQty>0){
                                productNameAreaHtml = [
                                    '<div class="Bflex1 priceArea_name">',
                                    '<h4>' + orderItem.goodsName + '</h4>',
                                    '<p class="smallFont_tip">',
                                    '<span>剩余'+order.giftRemainQty+'个未领取已退款</span>',
                                    '</p>',
                                    '</div>'].join("");
                            }else{
                                productNameAreaHtml = [
                                    '<div class="Bflex1 priceArea_name">',
                                    '<h4>' + orderItem.goodsName + '</h4>',
                                    '<p class="smallFont_tip">',
                                    '<span>已抢光</span>',
                                    '</p>',
                                    '</div>'].join("");
                            }
                            shareTaHtml = '<p class="shareTABtn"><a href="/shop/gift/multiGiftOrderEntryDetail?paymentOrderId='+order.paymentId+'" class="btnStyle btn_BorderGray">查看详情</a></p>';
                        }
                    }else{
                        var jifenHtml = '';
                        if(orderItem.isJifen != false){
                            if(orderItem.productPrice == 0){
                                jifenHtml = '<p class="priceAreaBox Bflex1"><span class="goodsPriceOld">￥'+ orderItem.memberPoint+'积分'+'</span></p>';
                            }else{
                                jifenHtml = '<p class="priceAreaBox Bflex1"><span class="goodsPriceOld">￥' + orderItem.productPrice + '+'+ orderItem.memberPoint+'积分'+'</span></p>';
                            }
                        }else{
                            jifenHtml = '<p class="priceAreaBox Bflex1"><span class="goodsPriceOld">￥' + orderItem.productPrice + '</span></p>';
                        }
                        productNameAreaHtml = ['           <div class="Bflex1 priceArea_name">',
                        '               <h4>' + orderItem.goodsName + '</h4>',
                        '               <p class="smallFont_tip"><span>规格:</span><span>已选择' + orderItem.productName + '</span></p>',
                            '           </div>'].join("");
                        productPriceAreaHtml = ['           <div class="priceArea_price HBox">',
                            jifenHtml,
                            '               <p class="selProNum"><span>×</span><span class="proNumber">' + orderItem.quantity + '</span></p>',
                            '           </div>'].join("");
                        shareTaHtml = "";
                    }
                    shtml += [
                        '<li>' +
                        '   <a class="BoxSelf" href="' + href + '">',
                        '       <figure>',
                        '           <img class="js_lazyImg fadeIn" data-echo="' + HTTP_IMAGE_URL + orderItem.goodsImage + smallImgArg200 +'" src="' + BASE_URL + '/static_v4/image/loadImg.jpg">',
                        '       </figure>',
                        '       <aside class="priceArea VBox Bflex1">',
                        productNameAreaHtml,
                        productPriceAreaHtml,
                        '       </aside>',
                        '   </a>',
                        shareTaHtml,
                        '</li>'].join("");
                }
            }
            shtmlBox=[  '<div class="orderProduction goods_showChangeBox">',
                '   <div class="goods_showChange">',
                '       <ul class="goodsList clearfix js_goodsList">' + shtml + '</ul>',
                '   </div>',
                '</div>'].join("");
            return shtmlBox;
        },
        gitfOrderTimer: function (timerBox) {
            var _this = this;
            var timerSecond = parseInt(timerBox.attr("data-timer"));
            var timerText = _this.formatTimer(timerSecond);
            timerBox.text(timerText);
            var tempTimerInterval = setInterval(function () {
                timerSecond -- ;
                var timerText = _this.formatTimer(timerSecond);
                timerBox.text(timerText);
                if(timerSecond <= 0){
                    clearInterval(tempTimerInterval);
                }
            },1000);
        },
        formatTimer: function (timerSecond) {
            var second =  timerSecond%60;
            var min = ((timerSecond - timerSecond%60)/60)%60;
            var honr = (timerSecond - timerSecond%3600)/3600;
            // console.log("%o  %o  %o  %o",timerSecond,honr,min,second);
            if(honr < 10){
                honr = "0" + honr;
            }
            if(min < 10){
                min = "0" + min;
            }
            if(second < 10){
                second = "0" + second;
            }
            var timerText = honr + ":" + min+":"+second;
            return timerText;
        },
        // 无订单页面
        noOrderPage:function () {
            var noHtml = '';
            noHtml =
                '<div class="errPage VBox" style="background: #f1f1f1">' +
                '   <div class="errImgBox halfImgBox">' +
                '       <figure class="errImg errImgFig" style="margin-top: 1rem;">' +
                '           <img src="'+BASE_URL+'/static_v4/image/wonderful/goods-null_trans.png" alt="">' +
                '       </figure>' +
                '   </div>' +
                '   <div class="errTxt Bflex1" style="margin-bottom: 1.5rem">' +
                '       <p>没有订单信息哦~</p>' +
                '       <p class="jumpHref"><a class="laterCome" href="'+BASE_URL+'/home">回首页</a></p>' +
                '   </div>' +
                '</div>';
            return noHtml
        }

    }
})